package com.tqjc.system.core.gate.asyn;

import com.tqjc.system.core.gate.service.SysGateService;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author 86195
 * @version 1.0
 * @description 打开道闸线程
 * @date 2023/10/29 15:29
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Slf4j
public class OpenGateThread extends Thread{

    private SysGateService sysGateService;

    private List<Integer> gateIndexList;

    private boolean flag = false;

    @Override
    public void run() {
        while (true) {
            try {

                for (Integer integer : gateIndexList) {
                    try {
                        sysGateService.openGate(integer);

                    } catch (Exception e) {
                        log.error("请求打开道闸异常",e);
                    }
                }
                if(flag){
                    break;
                }
                Thread.sleep(1*1000);
            } catch (Exception e){
                log.error("异常打开道闸线程异常",e);
            }
        }
    }


    public void closeGate(){
        flag = true;
    }
}
